package com.api.controller;


import com.api.annotation.Login;
import com.api.common.utils.Result;
import com.api.entity.TbCarousel;
import com.api.entity.TbMenu;
import com.api.service.ITbCarouselService;
import com.api.service.ITbMenuService;
import com.api.service.UploadService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 菜单 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-27
 */
@RestController
@RequestMapping("/menu")
@AllArgsConstructor
public class TbMenuController {
    private  final ITbMenuService menuService;


    /**
     * 新增
     */
    @Login
    @PostMapping
    @Operation(summary = "新增")
    public Result save(@RequestBody TbMenu menu) {
        menuService.save(menu);
        return new Result();
    }
    /**
     * 列表
     */
    @GetMapping
    @Operation(summary = "列表")
    public Result list(@RequestParam Integer client) {
        LambdaQueryWrapper<TbMenu> lwq = new LambdaQueryWrapper<>();
        lwq.eq(TbMenu::getClient,client);
        lwq.orderByDesc(TbMenu::getSort);
        List<TbMenu> list = menuService.list();
        return new Result().ok(list);
    }
    /**
     * 修改
     */
    @Login
    @PutMapping
    @Operation(summary = "修改")
    public Result update(@RequestBody TbMenu carousel) {
        menuService.updateById(carousel);
        return new Result();
    }
    /**
     * 删除
     */
    @Login
    @DeleteMapping("{id}")
    @Operation(summary = "删除")
    public Result update(@PathVariable Integer id) {
        menuService.removeById(id);
        return new Result();
    }
}
